package com.ruoyi.iot.task.health;

import com.ruoyi.iot.service.health.DeviceHealthScoreService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * 健康评分定时任务
 */
@Component("deviceHealthTask")
public class DeviceHealthTask {

    private static final Logger log = LoggerFactory.getLogger(DeviceHealthTask.class);

    private final DeviceHealthScoreService healthScoreService;

    public DeviceHealthTask(DeviceHealthScoreService healthScoreService) {
        this.healthScoreService = healthScoreService;
    }

    /**
     * 计算最新健康评分。
     */
    public void refreshScores() {
        log.debug("开始执行健康评分刷新任务");
        healthScoreService.calculateLatestScores();
    }

    /**
     * 汇总健康评分历史。
     */
    public void aggregateHistory() {
        log.debug("开始执行健康评分历史汇总任务");
        healthScoreService.aggregateDailyHistory();
    }
}
